package com.spzx.product;

import com.spzx.common.security.annotation.EnableCustomConfig;
import com.spzx.common.security.annotation.EnableRyFeignClients;
import com.spzx.product.domain.ProductSku;
import com.spzx.product.mapper.ProductSkuMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;

/**
 * 商品模块
 *
 * @author spzx
 */
@EnableCustomConfig
@EnableRyFeignClients
@SpringBootApplication
@MapperScan("com.spzx.*.mapper")
public class SpzxProductApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(SpzxProductApplication.class,args);
    }
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private ProductSkuMapper productSkuMapper;

    //Springboot应用初始化后会执行一次该方法
    @Override
    public void run(String... args) throws Exception {
        String key = "product:sku:data";
        //查询mysql里面商品skuId
        List<ProductSku> productSkuList = productSkuMapper.selectList(null);
        productSkuList.forEach(item -> {
            //添加到redis
            redisTemplate.opsForValue().setBit(key,item.getId(),true);
        });
    }
}